package com.ndp.fb.creative.fetchdata.util;

import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

/**
 * Created by evan.wan on 2015/5/8.
 */
public class ResponseUtils
{

    public static ResponseEntity<Object> ok(String flag, String msg, Object obj) {
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/json; charset=utf-8");
        OutResult outResult = new OutResult();
        if(StringUtils.isEmpty(flag.trim()))
        {
            outResult.setFlag("ok");
        }
        else
        {
            outResult.setFlag(flag);
        }
        if(StringUtils.isNotEmpty(msg))
        {
            outResult.setMsg(msg);
        }
        outResult.setData(obj);
        return new ResponseEntity<Object>(outResult, headers, HttpStatus.OK);
    }

    public static ResponseEntity<Object> ok(Object obj) {
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/json; charset=utf-8");
        OutResult outResult = new OutResult();
        outResult.setFlag("ok");
        outResult.setData(obj);
        return new ResponseEntity<Object>(outResult, headers, HttpStatus.OK);
    }

    public static ResponseEntity<Object> ok(String flag, String msg) {
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/json; charset=utf-8");
        OutResult outResult = new OutResult();
        if(StringUtils.isEmpty(flag.trim()))
        {
            outResult.setFlag("ok");
        }
        else
        {
            outResult.setFlag(flag);
        }
        if(StringUtils.isNotEmpty(msg))
        {
            outResult.setMsg(msg);
        }
        return new ResponseEntity<Object>(outResult, headers, HttpStatus.OK);
    }
}
